package demoComputer;

public class Computer {
    public void powerOn(){
        System.out.println("打开电脑");
    }
    public void powerOff(){
        System.out.println("关闭电脑");
    }
    //使用USB设备的方法,使用接口作为方法的参数
    public void useDevice(USB usb){
        usb.close();//打开设备
        if (usb instanceof Mouse){
            Mouse mouse =(Mouse) usb; //向下转型
            mouse.click();
        }else if (usb instanceof Keyboard){
            Keyboard keyboard =(Keyboard) usb;
            keyboard.type();
        }
        usb.open();//关闭设备
    }
}
